package reviews.task2;

import org.apache.hadoop.io.IntWritable;
import org.apache.hadoop.io.LongWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Mapper;

import java.io.IOException;

public class UserScoreMapper extends Mapper<LongWritable, Text, Text, IntWritable> {
    private IntWritable out_value = new IntWritable(1);
    @Override
    protected void map(LongWritable key, Text value, Context context) throws IOException, InterruptedException {
        try {
            // 1.拿到一行内容并转化为string后按照“,”对内容进行切割返回一个字符串数组
            String[] value_item = value.toString().split(",(?=([^\"]*\"[^\"]*\")*[^\"]*$)");
            if(value_item.length == 10){
                // 2. 将用户ID和1组合在一起并输出<key: 用户ID,value: 1>
                context.write(new Text(value_item[2]), out_value);
            }
        } catch (Exception e) {

        }
    }
}
